package com.ts.api.common.constant.app;

import com.gitee.apanlh.util.base.ArrayUtils;
import com.gitee.apanlh.util.valid.ValidParam;

/**
 *  APP-业务编码枚举
 *
 */
public enum AppBizCodeEnum {

    ESD_LARGE_LOAN("esdLargeLoan", new String[]{"1"},"e时代-大额贷"),
    ESD_CREDIT_LOAN("esdCreditLoan", new String[]{"1"}, "e时代-信用贷"),
    ;

    /** 业务编码 */
    private final String code;
    /** 限制流程流程标识 */
    private final String[] limitFlow;
    /** 业务名称 */
    private final String name;

    private AppBizCodeEnum(String code, String[] limitFlow, String name) {
        this.code = code;
        this.limitFlow = limitFlow;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String[] getLimitFlow() {
        return limitFlow;
    }

    public static AppBizCodeEnum getByCode(String code) {
        AppBizCodeEnum[] values = AppBizCodeEnum.values();
        for (AppBizCodeEnum appBizCodeEnum: values) {
            if (appBizCodeEnum.getCode().equals(code)) {
                return appBizCodeEnum;
            }
        }
        return null;
    }

    /**
     *  获取业务编码及对应限制流程
     *
     *  @param bizCode
     *  @param bizFlow
     *  @return boolean
     */
    public static AppBizCodeEnum getByCodeAndFlow(String bizCode, String bizFlow) {
        AppBizCodeEnum byCode = getByCode(bizCode);
        if (byCode == null || ValidParam.isNull(ArrayUtils.find(byCode.getLimitFlow(), bizFlow))) {
            return null;
        }
        return byCode;
    }
}
